package design.simdi.code.final_paper.site.panels.licente.admisi;

import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import design.simdi.code.final_paper.core.entities.Keyword;
import design.simdi.code.final_paper.site.panels.PagePanel;

/**
 * 
 * @author Marius Dumitriu - (Jun 23, 2010 - 12:55:34 AM)
 * 
 */
public class ViewAdmisDetails extends PagePanel {

	private static final long serialVersionUID = 1L;
	private Keyword keyword;

	private Label name;
	private MultiLineLabel description;
	private AjaxFallbackButton back;
	@SuppressWarnings("unchecked")
	private Form form;

	public ViewAdmisDetails(String id, IModel<Keyword> model) {
		super(id, model);

	}

	@SuppressWarnings("unchecked")
	@Override
	public void panelInit() {
		setOutputMarkupId(true);

		keyword = (Keyword) getDefaultModelObject();

		form = new Form("form");

		form.add(name = new Label("name", new PropertyModel<String>(keyword, "name")));
		form.add(description = new MultiLineLabel("description", new PropertyModel<String>(keyword, "description")));

		name.setEnabled(false);
		description.setEnabled(false);

		add(form);
		back = new AjaxFallbackButton("cancel", form) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				AdmisiTabPanel panel = new AdmisiTabPanel("panel");
				panel.setOutputMarkupId(true);

				Page page = this.getPage();

				page.get("content:tabs:panel").replaceWith(panel);

				target.addComponent(page);
			}
		};
		form.add(back);

	}

}
